# lib/stair_master/workflow_map/conditions/base.rb

module StairMaster
  module WorkflowMap
    module Rules
      class Base
        ## Attributes -------------------------------------
        attr_reader   :type # :if || :unless
        attr_accessor :method_name

        ## Initializer ------------------------------------
        def initialize(step, type, method_name)
          @step         = step
          @type         = type
          @method_name  = method_name
        end

        ## Methods ----------------------------------------

        def description
          raise NotImplementedError
        end

        def test(context)
          case @type.to_sym
          when :if
            return context.send(@method_name.to_sym)
          when :unless
            return !context.send(@method_name.to_sym)
          else
            return false
          end
        end
      end
    end
  end
end
